package com.session03;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class TestList {
    public static void main(String[] args) {
        List list = new ArrayList();
        //增加
        list.add("hello");
        list.add(new Date());
        list.add(100);
        list.add("hello");
        list.add(0, "world");//往指定位置插入元素
        System.out.println(list.size());

        //获取
        System.out.println(list.get(1));

        //修改
        list.set(0, "rj");
        System.out.println(list.get(0));

        //删除
        list.remove(0);
        list.remove("hello");//只删除一个
        System.out.println(list.get(0));
        System.out.println(list.size());

        list.clear();//全删
        System.out.println(list.size());

        System.out.println("---------------------");
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        //迭代器的作用
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            System.out.println(obj);
        }

        //泛型
        List<String> strList = new ArrayList<>();

    }
}
